<template>
	<view v-if="pageShow" class="container">
		<scroll-view refresher-background="#F6F7FB" :refresher-threshold="120" refresher-enabled="true"
			:refresher-triggered="isRefreshing" scroll-y="true" @refresherrefresh="reload"
			@scrolltolower="loadMore" class="mt-scroll">
			<view v-if="dataList.length > 0">
				<view class="content" v-for="(item, index) in dataList" :key="index">
					<view class="date">
						{{item.createtime}}
					</view>
					<view class="detail-item" @click="goViewDetail(item)">
						<view v-if="item.url" class="title">
							{{item.url == '1'?'小竹会员':item.url == '2'?'小竹叶':''}}
						</view>
						<view class="item-content" style="display: flex;">
							<mp-html
							:tagStyle="tagStyle"
							:content="item.info" 
							container-style="font-size: 32rpx;color: #787878;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;"></mp-html>
						</view>
					</view>
					<view v-if="item.url" class="view-detail solid-top" @click="goViewDetail(item)">
						{{item.url == '1'?'查看详情':item.url == '2'?'查看详情':''}}
					</view>
				</view>
				<uni-load-more :status="listStatus"></uni-load-more>
			</view>
			<view v-if="dataList.length === 0" class="empty-wrap" >
			  <image class="empty-img" src="https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/coupon/contentVanshi.png"></image>
			  <text class="tips">暂无通知</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import newsApi from "@/api/myNews.js"
	export default {
		data() {
			return {
				dataList: [],
				listStatus: 'more',
				page: 1,
				pageSize: 10,
				isRefreshing: false ,//界面下拉的状态
				pageShow: false,
				tagStyle: {
					em: 'font-style: normal;'
				}
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			async getList() {
				let obj = {
					type: 3,
					page: this.page,
					pagesize: this.pageSize
				}
				let res = await newsApi.getmessage(obj)
				if(res.code === 1) {
					let arr = []
					if (this.page == 1) {
						this.dataList = []
					}
					let newList = res.data
					if (newList.length >= this.pageSize) {
						this.listStatus = 'more'
					} else {
						this.listStatus = 'nomore'
					}
					let arr1 = arr.concat(newList)
					arr1.forEach(val => {
						let obj = {
							createtime: this.$moment(val.createtime*1000).format('MM-DD'),
							url: val.url,
							title: val.title,
							id: val.id,
							info: val.info
						}
						this.dataList.push(obj)
					})
					this.isRefreshing = false
					this.pageShow = true
				}
			},
			
			//下拉刷新
			reload() {
				this.isRefreshing = true;
				this.page = 1
				this.getList()
			},
			
			loadMore() {
				console.log('有没有走加载更多')
				if (this.listStatus == 'more') {
					this.page += 1
					this.getList()
				}
			},
			
			//跳转详情
			goViewDetail(val) {
				if(val.url == '1') {
					uni.navigateTo({
						url: '/pagesMy/my/vip/index'
					})
				}else if(val.url == '2') {
					uni.navigateTo({
						url: '/pagesMy2/my/bamboo/index'
					})
				}
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	@import "newsDetail.scss";
</style>
